string(REGEX MATCH "([LT0-9.]+)$" MAYA_VERSION "${CMAKE_CURRENT_SOURCE_DIR}")
string(REGEX MATCH "([0-9.]+)$" MAYA_YEAR ${MAYA_VERSION})
string(REGEX MATCH "LT" MAYA_LT ${MAYA_VERSION})
set(MESHSYNC_CLIENT_MAYA "MeshSyncClientMaya${MAYA_VERSION}")
find_package(Maya${MAYA_VERSION})

file(GLOB sources *.cpp *.h)
add_library(${MESHSYNC_CLIENT_MAYA} SHARED ${sources})
add_dependencies(${MESHSYNC_CLIENT_MAYA} MeshUtils MeshSync)
target_include_directories(${MESHSYNC_CLIENT_MAYA} PUBLIC "${CMAKE_SOURCE_DIR}" "${MAYA${MAYA_VERSION}_INCLUDE_DIR}")
target_link_libraries(${MESHSYNC_CLIENT_MAYA} MeshSync MeshUtils ${Poco_LIBRARIES} ${MAYA${MAYA_VERSION}_LIBRARIES})
if(ENABLE_ZSTD)
    target_link_libraries(${MESHSYNC_CLIENT_MAYA} ${ZSTD_LIBRARY})
endif()
if(${MAYA_VERSION} MATCHES "LT")
    add_definitions(-DMAYA_LT=1)
else()
    add_definitions(-DMAYA_LT=0)
endif()
if(LINUX)
    target_link_libraries(${MESHSYNC_CLIENT_MAYA} pthread "-Wl,--no-undefined")
elseif(MAC)
    set_target_properties(${MESHSYNC_CLIENT_MAYA} PROPERTIES COMPILE_FLAGS -DOSMac_)
    set_target_properties(${MESHSYNC_CLIENT_MAYA} PROPERTIES SUFFIX ".bundle")
endif()
set_target_properties(${MESHSYNC_CLIENT_MAYA} PROPERTIES PREFIX "")
set_target_properties(${MESHSYNC_CLIENT_MAYA} PROPERTIES OUTPUT_NAME "MeshSyncClientMaya")

if(LINUX)
    set(DIST_DIR "${CMAKE_INSTALL_PREFIX}/UnityMeshSync_Maya${MAYA_LT}_${PLATFORM}/modules")
elseif(MAC)
    set(DIST_DIR "${CMAKE_INSTALL_PREFIX}/UnityMeshSync_Maya${MAYA_LT}_${PLATFORM}")
endif()
set(CONTENT_DIR "${DIST_DIR}/UnityMeshSync/${MAYA_YEAR}${MAYA_LT}")

install(TARGETS ${MESHSYNC_CLIENT_MAYA} DESTINATION "${CONTENT_DIR}/plug-ins/")
install(DIRECTORY MEL/ DESTINATION "${CONTENT_DIR}/scripts/" FILES_MATCHING PATTERN "*.mel")
install(DIRECTORY MEL/ DESTINATION "${DIST_DIR}/" FILES_MATCHING PATTERN "*.mod")